<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>冒泡排序</title>
</head>
<body>
<script>
    var arr = [123,14,5,87,56,245,156];
    for(var i = 0;i<arr.length-1;i++){
        for(var q = 0;q<arr.length-1-i;q++){
            //如果前面一个数大于后面一个数，那么就给这2个数交换位置
            if(arr[q] > arr[q + 1]){
                var temp = arr[q];
                arr[q] = arr[q + 1];
                arr[q + 1] = temp;
            }
        }
    }
    console.log(arr);
</script>
</body>
</html>